//
//  BKGDMainFooterRefreshView.m
//  bestkeep
//
//  Created by 武探 on 2016/12/13.
//  Copyright © 2016年 utouu. All rights reserved.
//

#import "BKGDMainFooterRefreshView.h"
#import "BKGDCommon.h"

//@interface BKGDMainFooterRefreshView()
//
//@property(nonatomic,strong) CAShapeLayer *arrowLayer;
//@property(nonatomic,strong) UILabel *titleLabel;
//
//@end
//
//@implementation BKGDMainFooterRefreshView
//
//-(instancetype)initWithFrame:(CGRect)frame {
//    if(CGRectEqualToRect(CGRectZero, frame)) {
//        frame = CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, 200);
//    }
//    self = [super initWithFrame:frame];
//    if(self) {
//        [self initialize];
//    }
//    return self;
//}
//
//-(void)initialize {
//    
//    self.backgroundColor = [UIColor whiteColor];
//    
//    UIColor *color = [UIColor grayColor];
//    
//    _arrowLayer = [[CAShapeLayer alloc] init];
//    _arrowLayer.lineCap = kCALineCapRound;
//    _arrowLayer.lineJoin = kCALineJoinBevel;
//    _arrowLayer.lineWidth = 1;
//    _arrowLayer.strokeColor = color.CGColor;
//    _arrowLayer.fillColor = [UIColor clearColor].CGColor;
//    [self.layer addSublayer:_arrowLayer];
//    
//    _titleLabel = [[UILabel alloc] init];
//    _titleLabel.text = BKGDLocalizedString(@"BKGDMainFooterRefreshTitle");
//    _titleLabel.textColor = color;
//    _titleLabel.font = UIFontNormal;
//    [self addSubview:_titleLabel];
//}
//
//-(void)layoutSubviews {
//    [super layoutSubviews];
//    
//    NSString *title = _titleLabel.text;
//    CGSize size = [title sizeWithAttributes:@{NSFontAttributeName: _titleLabel.font}];
//    CGFloat width = size.width;
//    _titleLabel.frame = CGRectMake(CGRectGetWidth(self.frame) / 2 - width / 2, 12, width, _titleLabel.font.lineHeight);
//    
//    _arrowLayer.path = [self arrowPath].CGPath;
//}
//
//-(UIBezierPath*)arrowPath {
//    
//    UIBezierPath *path = [UIBezierPath bezierPath];
//    [path moveToPoint:CGPointMake(CGRectGetMinX(_titleLabel.frame) - 5, CGRectGetMaxY(_titleLabel.frame) - 5)];
//    [path addLineToPoint:CGPointMake(CGRectGetMinX(_titleLabel.frame) - 5 - 6, CGRectGetMinY(_titleLabel.frame) + 5)];
//    [path addLineToPoint:CGPointMake(CGRectGetMinX(_titleLabel.frame) - 5 - 12, CGRectGetMaxY(_titleLabel.frame) - 5)];
//    return path;
//}
//
//@end

#define BKGDMainFooterRefreshViewDefaultHeight 160

@interface BKGDMainFooterRefreshView()

@property(nonatomic,strong) UILabel *titleLabel;
@property(nonatomic,strong) CALayer *leftLayer;
@property(nonatomic,strong) CALayer *rightLayer;

@end

@implementation BKGDMainFooterRefreshView

-(instancetype)initWithFrame:(CGRect)frame {
    if(CGRectEqualToRect(CGRectZero, frame)) {
        frame = CGRectMake(0, 0, CGRectGetWidth([[UIScreen mainScreen] bounds]), BKGDMainFooterRefreshViewDefaultHeight);
    }
    self = [super initWithFrame:frame];
    if(self) {
        [self initialize];
    }
    return self;
}

-(void)initialize {
    _titleLabel = [[UILabel alloc] init];
    _titleLabel.text = BKGDLocalizedString(@"BKGDMainFooterRefreshTitle");
    _titleLabel.textColor = [UIColor colorWithRed:0.545 green:0.545 blue:0.545 alpha:1.00];
    _titleLabel.font = [UIFont systemFontOfSize:12];
    [self addSubview:_titleLabel];
    
    _leftLayer = [[CALayer alloc] init];
    _leftLayer.backgroundColor = [UIColor colorWithRed:0.878 green:0.878 blue:0.878 alpha:1.00].CGColor;
    [self.layer addSublayer:_leftLayer];
    
    _rightLayer = [[CALayer alloc] init];
    _rightLayer.backgroundColor = _leftLayer.backgroundColor;
    [self.layer addSublayer:_rightLayer];
    
}

-(void)layoutSubviews {
    [super layoutSubviews];
    
    CGSize titleSize = [_titleLabel.text sizeWithAttributes:@{NSFontAttributeName: _titleLabel.font}];
    
    _titleLabel.frame = CGRectMake(CGRectGetWidth(self.frame) / 2 - titleSize.width / 2, 8, titleSize.width, 16);
    
    CGFloat lineHeight = 1 / [[UIScreen mainScreen] scale];
    CGFloat lineWidth = 50;
    
    _leftLayer.frame = CGRectMake(CGRectGetMinX(_titleLabel.frame) - lineWidth - 5, CGRectGetMinY(_titleLabel.frame) + CGRectGetHeight(_titleLabel.frame) / 2, lineWidth, lineHeight);
    
    _rightLayer.frame = CGRectMake(CGRectGetMaxX(_titleLabel.frame) + 5, CGRectGetMinY(_leftLayer.frame), CGRectGetWidth(_leftLayer.frame), CGRectGetHeight(_leftLayer.frame));
}

@end



